﻿using FrameworkTemplate.Windows;
using FrameworkTemplate.Workers;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using User;

namespace FrameworkTemplate
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        MainWindow window;

        /// <summary>
        /// 应用程序启动事件
        /// </summary>
        /// <param name="e"></param>
        protected override void OnStartup(StartupEventArgs e)
        {
            //暂时取消重复关闭
            CloseMultiProcess();
            Login login = new Login(ref GLOBAL.user);
            window = new MainWindow();


            login.ShowDialog();
            if (GLOBAL.user.right > Right.None)
            {
                window.Show();
            }
            else
            {
                window.DirectClose();
            }
            

        }
        /// <summary>
        /// 仅允许开启一个应用窗口(关闭多开程序)
        /// </summary>
        private void CloseMultiProcess()
        {
            Process process = Process.GetCurrentProcess();
            if (Process.GetProcessesByName(process.ProcessName).Count() > 1)
                this.Shutdown();
        }
        protected override void OnExit(ExitEventArgs e)
        {
            //GLOBAL.StopAll();
        }
    }
}
